﻿using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

namespace Landsat8_LSTWindow
{
    public class StandardHttpClient
    {
        private HttpClient _client;

        public StandardHttpClient()
        {
            _client = new HttpClient();
        }

        public async Task<string> GetStringAsync(string uri)
        {
            var requestMessage = new HttpRequestMessage(HttpMethod.Get, uri);

            var response = await _client.SendAsync(requestMessage);

            return await response.Content.ReadAsStringAsync();
        }

        public async Task<HttpResponseMessage> PostFormAsync(string uri, AtmCorrParam item)
        {
            System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            var requestMessage = new HttpRequestMessage(HttpMethod.Post, uri);
            requestMessage.Content = new StringContent(item.ToFormUrlEncodedString(), System.Text.Encoding.UTF8, "application/x-www-form-urlencoded");
            var response = await _client.SendAsync(requestMessage);
            return response;
        }

        public async Task<HttpResponseMessage> DeleteAsync(string uri)
        {
            var requestMessage = new HttpRequestMessage(HttpMethod.Delete, uri);
            return await _client.SendAsync(requestMessage);
        }

    }
}

